<?php
    session_start();
    $reportMember=$_SESSION["report"]["member"];
?>
<style type="text/css">
    #navBarAdmin, #navBarFarmer{
        display: none;
    }
</style>
<script type="text/javascript">
    
    function showCrop(){
        $.post('report/memberList/memberListTable.php',{
            startYear: startYear,
            keyword: $('#keyword').val()
        },function(data){
            $('#cropList').html(data);
        });
    }
    
   
    var startYear='';
    function setYear(stYear){
        startYear=stYear;
        $('#startYear').html(stYear);
    }
</script>

<div class="myNav" style="height: 52px;">
    <div class="myNav-heading" style="padding: 0px;">
        <div class="btn-primary" style="width: 100%;float: left;text-align: center;border-right: 1px solid #fff;padding: 10px;text-align: left;"
            onclick="home()">
            <span class="glyphicon glyphicon-chevron-left"></span> กลับ
        </div>
    </div>
</div>
<div id="inputForm">
    <div class="col-md-6" style="padding: 5px;"></div>
    <div class='col-md-6' style="padding: 5px;">
        <div class="input-group">
            <span class="input-group-addon">
                <span class="glyphicon glyphicon glyphicon-search" aria-hidden="true"></span>
            </span>
            <input id="keyword" type="text" class="form-control" placeholder="ค้นหาเกษตร">
            <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span id='startYear'>ปีที่เริ่มปลูก</span> <span class="caret"></span></button>
                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                    <li><a href="javascript:setYear('');$('#startYear').html('ทั้งหมด');showCrop();">ทั้งหมด</a></li>
                    <li class="divider"></li>
                    <?php
                        $query="
                            select	year(startDate) as startYear
                            from	member_farm_crop
                            where	farmID in (
                                            select  farmID
                                            from    member_farm
                                        )
                            group by	startYear
                            ";
                        $result=$mysqli->query($query);
                        while($row=$result->fetch_array(MYSQLI_ASSOC)){
                            ?>
                    <li><a href="javascript:setYear('<?=$row["startYear"]?>');showCrop();"><?=$row["startYear"]?></a></li>
                                <?php
                        }
                    ?>
                </ul>
            </div><!-- /btn-group -->
        </div>
    </div>
    <div id="cropList" class='col-md-12' style="padding: 0px;"></div>
</div>
<script type="text/javascript">
    showCrop();
    $('#keyword').keyup(function(){
        showCrop();
    });
</script>